Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
request-progress
Advanced tools
The request-progress npm package is used to track the progress of HTTP requests made using the request library. It provides a simple way to monitor the progress of file uploads and downloads, giving you real-time feedback on the status of your requests.
Track Download Progress
This feature allows you to track the progress of a file download. The 'progress' event provides real-time updates on the download status, including the percentage completed, speed, and remaining time.
const request = require('request');
const progress = require('request-progress');
progress(request('http://example.com/file.zip'))
.on('progress', function (state) {
console.log('progress', state);
})
.on('error', function (err) {
console.error('error', err);
})
.on('end', function () {
console.log('Download completed');
});
Track Upload Progress
This feature allows you to track the progress of a file upload. The 'progress' event provides real-time updates on the upload status, including the percentage completed, speed, and remaining time.
const fs = require('fs');
const request = require('request');
const progress = require('request-progress');
const fileStream = fs.createReadStream('path/to/file.zip');
progress(request.post('http://example.com/upload', { formData: { file: fileStream } }))
.on('progress', function (state) {
console.log('progress', state);
})
.on('error', function (err) {
console.error('error', err);
})
.on('end', function () {
console.log('Upload completed');
});
The progress-stream package provides a way to monitor the progress of data being streamed. It can be used with any stream, not just HTTP requests, making it more versatile than request-progress. However, it requires more manual setup to integrate with HTTP requests.
The axios-progress-bar package is designed to work with the axios HTTP client. It provides a progress bar for file uploads and downloads, similar to request-progress. It is a good alternative if you are using axios instead of the request library.
Tracks the download progress of a request made with request.
$ npm install request-progress
var fs = require('fs');
var request = require('request');
var progress = require('request-progress');
// Note that the options argument is optional
progress(request('http://google.com/doodle.png'), {
throttle: 2000, // Throttle the progress event to 2000ms, defaults to 1000ms
delay: 1000 // Only start to emit after 1000ms delay, defaults to 0ms
})
.on('progress', function (state) {
console.log('received size in bytes', state.received);
// The properties bellow can be null if response does not contain
// the content-length header
console.log('total size in bytes', state.total);
console.log('percent', state.percent);
})
.on('error', function (err) {
// Do something with err
})
.pipe(fs.createWriteStream('doodle.png'))
.on('error', function (err) {
// Do something with err
})
.on('close', function (err) {
// Saved to doogle.png!
})
Note that the state
object emitted in the progress
event is reused to avoid creating a new object for each event.
Released under the MIT License.
FAQs
Tracks the download progress of a request made with mikeal/request, giving insight of various metrics including progress percent, download speed and time remaining
The npm package request-progress receives a total of 4,560,094 weekly downloads. As such, request-progress popularity was classified as popular.
We found that request-progress demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.